package rx.genarator.comprehension;

import java.util.HashSet;
import java.util.Set;

public class Column {

	private String id;
	private String name;
	private String code;
	private String comment;
	private TableOrView tableOrView;
	private String dataType;
	private boolean mandatory;
	private Sequence sequence;
	  
	private Reference start;
	private Set<Reference> ends = new HashSet<Reference>();
  
	public Column(TableOrView tableOrView,String id, String name, String code,String comment,String dataType,boolean mandatory) {
		super();
		if(tableOrView == null || id == null || name == null || code == null || dataType == null)
			throw new IllegalArgumentException("tableOrView:"+ tableOrView + ",id:" + id + ",name:" + name + ",code:" + code + ",comment:" + comment+",dataType:" + dataType +",mandatory:" + mandatory);
		this.id = id;
		this.name = name;
		this.code = code;
		this.comment = comment;
		this.tableOrView = tableOrView;
		this.dataType = dataType;
		this.mandatory = mandatory;
		ObjectsMap.put(id, this);
	}
	
	void setStart(Reference start){
		this.start = start;
	}
	
	synchronized void addEnd(Reference end){
		this.ends.add(end);
	}
	
	synchronized boolean removeEnd(Reference end){
		return this.ends.remove(end);
	}

	public String getCode() {
		return code;
	}

	public String getComment() {
		return comment;
	}

	public String getId() {
		return id;
	}

	public String getName() {
		return name;
	}

	public TableOrView getTableOrView() {
		return tableOrView;
	}
	
	public Reference getStart(){
		return this.start;
	}
  
	public Set<Reference> getEnds(){
		return new HashSet<Reference>(this.ends);
	}

	public String getDataType() {
		return dataType;
	}

	public boolean isMandatory() {
		return mandatory;
	}

	public Sequence getSequence() {
		return sequence;
	}

	public void setSequence(Sequence sequence) {
		this.sequence = sequence;
	}
}
